from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop, Camera, Gallery


class PreTest_RK3568_Basic_Setting_4000(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.进入桌面-设置-系统，点击恢复出厂设置
    # 2.点击重置设备
    # 预期结果：
    # 1.进入恢复出厂设置
    # 2.重置后保存的应用与数据清除，可重新进入桌面

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)
        Step('预置条件2：拍一张照片')
        CommonOH.startAbility(self.Phone1, Camera.ability_name, Camera.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '拍照')
        CommonOH.click(self.Phone1, **Camera.shot_button)

    def process(self):
        Step('步骤1：进入桌面-设置-系统，点击恢复出厂设置')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '系统')
        CommonOH.touchByText(self.Phone1, '恢复出厂设置')
        Step('预期结果1：进入恢复出厂设置')
        CommonOH.checkIfTextExist(self.Phone1, '重置设备')

        Step('步骤2：点击重置设备')
        # 第一个是恢复出厂设置页面的重置，第二个相当于确认重置，两个不在同一个页面
        CommonOH.touchByText(self.Phone1, '重置设备')
        CommonOH.touchByText(self.Phone1, '重置设备', index=1)
        CommonOH.wait(self.Phone1, 0.5)
        Step('预期结果2: 重置后保存的应用与数据清除，可重新进入桌面')
        CommonOH.waitForBootCompletion(self.Phone1)
        CommonOH.wake(self.Phone1)
        CommonOH.startAbility(self.Phone1, Gallery.ability_name, Gallery.bundle_name)
        CommonOH.checkIfTextExist(self.Phone1, '查看按时间分组的照片')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
